package com.mini.framework.communicate.mina.utils;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPool {

	private int core = 10;

	private int max = 100;

	private long aliveTime = 3;
	
	private int queue = 10;

	private ThreadPoolExecutor executor;
	
	private static ThreadPool instance; 

	private ThreadPool() {
		executor = new ThreadPoolExecutor(core, max, aliveTime, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(queue),new ThreadPoolExecutor.DiscardOldestPolicy());
	}
	
	public static ThreadPool getInstance(){
		if(instance == null){
			instance = new ThreadPool();
		}
		return instance;
	}
	
	public void fire(Runnable task){
		executor.execute(task);
	}

}
